//
//  ZBYVistor.swift
//  新浪微博
//
//  Created by zby on 16/2/25.
//  Copyright © 2016年 zby. All rights reserved.
//

import UIKit
import SnapKit
class ZBYVistor: UIView {
    
    //重写init with frame方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
        backgroundColor = UIColor(white: 237/255.0, alpha: 1)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //创建一个方法，创建视图并布局
    func setUpUI(){
        
        //添加子控件
        addSubview(homeIconImageView)
        addSubview(iconImageView)
        addSubview(messageLabel)
        addSubview(registerButton)
        addSubview(loginButton)
        addSubview(maskImageView)
        
        //布局子控件
        homeIconImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self.snp_center)
        }
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self.snp_center)
        }
        maskImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self.snp_center)
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(homeIconImageView.snp_bottom).offset(10)
            make.centerX.equalTo(self.snp_centerX)
            make.width.equalTo(216)
        }
        registerButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(messageLabel.snp_left)
            make.top.equalTo(messageLabel.snp_bottom).offset(10)
            make.width.equalTo(100)
            make.height.equalTo(30)
        }
        loginButton.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(messageLabel.snp_right)
            make.top.equalTo(messageLabel.snp_bottom).offset(10)
            make.width.equalTo(100)
            make.height.equalTo(30)
        }
    }
    
    //懒加载
    //动画视图
    lazy var homeIconImageView : UIImageView = {
        let imageV = UIImageView()
        imageV.image = UIImage(named: "visitordiscover_feed_image_smallicon")
        return imageV
    }()
    
    //基本视图
    lazy var iconImageView : UIImageView = {
        let iconV = UIImageView()
        iconV.image = UIImage(named: "visitordiscover_feed_image_house")
        return iconV
    }()
    
    //文本信息
    lazy var messageLabel : UILabel = {
        let messL = UILabel()
        messL.text = "关注一些人，回这里看看有什么惊喜"
        messL.font = UIFont.systemFontOfSize(16)
        messL.textAlignment = .Center
        messL.textColor = UIColor.grayColor()
        return messL
    }()
    
    //注册按钮
    lazy var registerButton : UIButton = {
        let button = UIButton(type: UIButtonType.Custom)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        button.setTitle("注册", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        button.addTarget(self, action: "register", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
    
    //登录按钮
    lazy var loginButton : UIButton = {
        let button = UIButton(type: UIButtonType.Custom)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        button.setTitle("登录", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        button.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
    
    //遮罩视图
    lazy var maskImageView : UIImageView = {
        let maskV = UIImageView()
        maskV.image = UIImage(named: "visitordiscover_feed_mask_smallicon")
        return maskV
    }()
    
    //添加动画
    func startAnimation(){
        let animation = CABasicAnimation(keyPath: "transform.rotation")
        animation.toValue = 2 * M_PI
        animation.repeatCount = MAXFLOAT
        animation.duration = 10
        animation.removedOnCompletion = false
        
        homeIconImageView.layer.addAnimation(animation, forKey: nil)
    }
}








